#ifndef __MUTEX_H__
#define __MUTEX_H__


#include "../SyncMethod/IMethod.h"


namespace Sync
{

class Mutex : public IMethod
{
	HANDLE _mutex;


public :
	Mutex( const char* sync_title ) : IMethod( sync_title ) {}
	virtual ~Mutex( void ) {}


	virtual void release( void ) override
	{
		CloseHandle( _mutex );
	}

	virtual void initialize( void ) override
	{
		_mutex = CreateMutex( 0, FALSE, 0 );

		std::cout << name().c_str() << std::endl;
	}

	virtual bool lock( void ) override
	{
		WaitForSingleObject( _mutex, INFINITE );

		return true;
	}

	virtual void unlock( void ) override
	{
		ReleaseMutex( _mutex );
	}
};

};

#endif